package com.xr.controller;


import com.xr.exception.CustomException;
import com.xr.result.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice

public class BaseExceptionAdvice {
    /**
     * 自定义的异常处理
     */
    @ExceptionHandler(CustomException.class)
    public Result handleCustomException(CustomException ex){
        return new Result(false, ex.getMessage());
    }
    /**
     * 所有未知的异常
     */
    @ExceptionHandler(Exception.class)
    public Result handleException(Exception ex){
        return new Result(false,ex.getMessage()=="Access is denied"?"                     权限不足":"发生未知错误,请联系管理员！");

    }

    /**
     * 系统异常
     * @param ex
     * @return
     */
//    @ExceptionHandler(Exception.class)
//    public Result handleCustomException(Exception ex){
//        System.out.println("进这里了.....");
//        return new Result(false,ex.getMessage());
//    }
}
